let longestSubstring = (str) => {
    if (!str) return 0;
    let set = new Set();
    let l = 0;
    let res = 0;
    for (let r = 0; r < str.length; r++) {
        // 如果当前字符出现过
        if (set.has(str[r])) {
            while (set.has(str[r])) {
                set.delete(str[l]);
                l += 1;
            }
        }
        set.add(str[r]);
        res = Math.max(res, r - l + 1);
    }
    return res;
}

let str = "abccdeffabc";
console.log(longestSubstring(str))